/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 2 -*- */
/**
* @headerfile timer.hpp
* 
* Header for control the time elapsed.
*
* @author Miguel Ángel Vílchez López 2010 <sacra@openmatica.es>
*
* Idea got from cc.byexamples.com.
* @sa http://cc.byexamples.com/20070314/create-a-timer/
*
* Codigo is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* Codigo is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along
* with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _MOKARDU_TIMER_HPP_
#define _MOKARDU_TIMEr_HPP_

#include <math.h>
#include <stdio.h>
#include <sys/time.h>

/**
* @class CMTimer
* @brief Programing timers.
*/

class CMTimer
{

	private:
	
		/**
		* The microseconds to wait.
		*/
		unsigned long int usec;
		
		/**
		* The seconds to wait.
		*/
		unsigned long int sec;
		
		/**
		* The variable to manage the time.
		*/
		struct timeval tv_end;
		
		/**
		* The function to update the tv_end with the microseconds and seconds we want to wait.
		*/
		void setTimerUsec();


	public:
	
		/**
		* Constructor.
		*/
		CMTimer(unsigned long int usec);
		
		/**
		* Destructor.
		*/
		~CMTimer();
		
		/**
		* The function that checks if the time has elapsed.
		* @return 1 if the time has elapsed else return 0.
		*/
		int check();
		 
};

#endif // _MOKARDU_TIMER_HPP_
